package a630wj.recycleview630wj.model;

/**
 * Created by weijie on 2017/6/8.
 */

import java.util.List;

import a630wj.recycleview630wj.bean.VideoBean;
import a630wj.recycleview630wj.iface.VideoListener;
import a630wj.recycleview630wj.service.VideoService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class VideoModel {
    private static Retrofit retrofit;
    private String BASEURL = "http://amicool.neusoft.edu.cn";

    public VideoModel() {
        retrofit = new Retrofit.Builder().baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }
    public static void getResultList(String mod, int page, String sessionID, final VideoListener listener) {
        VideoService articeservice =retrofit.create(VideoService.class);
        Call<List<VideoBean>> call= articeservice.getArticleList(mod,page,sessionID);
        call.enqueue(new Callback<List<VideoBean>>() {
            @Override
            public void onResponse(Call<List<VideoBean>> call, Response<List<VideoBean>> response) {
                if(response.isSuccessful()&&response.body()!=null)
                {
                    listener.onResponse(response.body());
                }
                else
                {
                    listener.onFail("FAIL");
                }
            }

            @Override
            public void onFailure(Call<List<VideoBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });

    }
}
